package cn.cloudplug.instar_ec.accessional.picture;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.view.View;
import android.widget.RelativeLayout;

import java.io.File;

import cn.cloudplug.core.manage.picture.Callback;
import cn.cloudplug.core.manage.picture.PicInfoPacket;
import cn.cloudplug.core.manage.picture.PictureManager;
import cn.cloudplug.core.util.MyUtil;
import cn.cloudplug.instar_ec.R;
import cn.cloudplug.ui.delegate.spinner.SpinnerBaseDelegate;

/**
 * Created by pc on 2018/1/23.
 */

public class AlbumDelegate extends SpinnerBaseDelegate implements Callback,View.OnClickListener {

    AppCompatImageView imageView;
    private PicControlMode picControlMode;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PictureManager.getInstance().getPicList(this);
        picControlMode = new PicControlMode(getSupportDelegate().getActivity());
    }

    @Override
    public void addViewToToolbar(RelativeLayout group) {
        int pxi=MyUtil.DipToPixels(getContext(),20);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(pxi,pxi);
        params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params.addRule(RelativeLayout.CENTER_VERTICAL);
        imageView=new AppCompatImageView(getContext());
        imageView.setImageResource(R.mipmap.icon_dustbin);
        group.addView(imageView,params);
        imageView.setOnClickListener(this);
    }

    @Override
    public void onPostExecute(PicInfoPacket picInfoPacket) {
        addBean("所有相片",new PictureDelegate().setData(picInfoPacket.getAllPic()).setMode(picControlMode));
        for(File folder : picInfoPacket.getData().keySet()){
            addBean(folder.getName(),new PictureDelegate().setData(picInfoPacket.getData().get(folder)).setMode(picControlMode));
        }
    }

    @Override
    public void onClick(View v) {
        if(picControlMode.getMode()==PicControlMode.MODEL_DEFAULT){
            picControlMode.setMode(PicControlMode.MODEL_DELETE);
        }else{
            picControlMode.setMode(PicControlMode.MODEL_DEFAULT);
        }
    }
}
